package com.vsen.lpr.task;


import com.vsen.lpr.common.utils.DateTimeUtil;
import com.vsen.lpr.common.utils.SmsUtil;
import com.vsen.lpr.entity.TaskPlan;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.Date;


@Component
public class DelayTaskConsumer implements ApplicationRunner {
    @Override
    public void run(ApplicationArguments args) throws Exception {
        while (true) {//持续读取
            System.out.println("");
            System.out.println("");
            System.out.println("开始读取---");
            DelayTask take = TaskUtil.queue.take();
            TaskPlan taskPlan = take.getData();
            String startTime = DateTimeUtil.format(taskPlan.getExecuteTine(),"yyyy年MM月dd号 HH点mm分ss秒");
            String endTime = DateTimeUtil.format(taskPlan.getEndTime(),"yyyy年MM月dd号 HH点mm分ss秒");
            if("0".equals(taskPlan.getIsRemind())){
                SmsUtil.smsTask(taskPlan.getUserId(),startTime,endTime,taskPlan.getName());
            }
            System.err.println(take.getData().getContext());
            Date date = new Date(take.getData().getRemindTime().getTime());
            String time = DateTimeUtil.format(date, "yyyy/MM/dd HH:mm:ss");
            System.err.println("----------" + time);
            System.out.println("=====结束======");
            System.out.println("");
            System.out.println("");
        }
    }
}
